from commons.entity.po.reimbursement import Reimbursement
from commons.entity.po.user import User

from commons.entity.po.model import db


class ReimbursementApprovalFi(db.Model):
    __tablename__ = 'reimbursement_approval_fi'

    reimbursement_approval_fi_id = db.Column(db.Integer, primary_key=True, autoincrement=True,
                                             info='财务人员审批报销申请编号')
    reimbursement_id = db.Column(db.ForeignKey(
        'reimbursement.reimbursement_id'), index=True, info='报销申请编号')
    payment = db.Column(db.Float, info='报销款金额')
    finance_id = db.Column(db.ForeignKey('user.user_id'),
                           index=True, info='财务人员编号')
    date = db.Column(db.Date, info='审批时间')

    finance = db.relationship('User', primaryjoin='ReimbursementApprovalFi.finance_id == User.user_id',
                              backref='reimbursement_approval_fis')
    reimbursement = db.relationship('Reimbursement',
                                    primaryjoin='ReimbursementApprovalFi.reimbursement_id == '
                                                'Reimbursement.reimbursement_id',
                                    backref='reimbursement_approval_fis')

    def to_dict(self):
        return {
            'reimbursement_approval_fi_id': self.reimbursement_approval_fi_id,
            'reimbursement_id': self.reimbursement_id,
            'payment': self.payment,
            'finance_id': self.finance_id,
            'date': self.date.isoformat() if self.date else None
        }

    def to_dict_2(self):
        return {
            'reimbursementApprovalFiId': self.reimbursement_approval_fi_id,
            'reimbursementId': self.reimbursement_id,
            'payment': self.payment,
            'financeId': self.finance_id,
            'date': self.date.isoformat() if self.date else None
        }
